﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class LoaiMonAnDAO
    {
        public static bool Insert(LoaiMonAnDTO lma)
        {
            bool result = false;

            string strSQLEmployee = "Insert into LoaiMonAn(TenLoai) values (@Ten)";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@Ten", lma.TenLoai));
                // Call execute none query

                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);//.ExecuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static bool Update(LoaiMonAnDTO lma)
        {
            bool result = false;

            string strSQLEmployee = "Update LoaiMonAn set TenLoai=@TenLoai Where MaLoai=@MaLoai";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaLoai", lma.MaLoai));
                sqlParams.Add(new SqlParameter("@TenLoai", lma.TenLoai));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static bool Delete(int MaLMA)
        {
            bool result = false;
            string strSQLEmployee = "DELETE FROM LoaiMonAn WHERE MaLoai=@MaLoai";
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaLoai", MaLMA));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static DataTable SelectAll()
        {
            String strSql = "Select * from LoaiMonAn";

            try
            {
                DataTable dt = SqlDataAccessHelper.ExcuteQuery(strSql);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
